﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLayer.Class;
using System.Collections;

namespace DataLayer.Database
{
    public class MasaDB
    {

        public static ArrayList tumMasalariCek(string aranan, int kriter,DateTime? tarih)
        {
            DBConnection cn = new DBConnection();
            ArrayList masalar = new ArrayList();
            
            foreach(TumMasalariCek_Result1 m in cn.ConnectDB.TumMasalariCek(aranan,kriter))
                masalar.Add(new Masa(m.MasaID,m.Kapasite,rezervasyonDurumuBelirle(m.MasaID,tarih), new MasaTipi(m.MasaTipiID,m.TipAdi,m.Katsayi,m.Resim)));

            return masalar;
        }

        private static bool rezervasyonDurumuBelirle(int masaID,DateTime? tarih)
        {
            int deger = 0;
            foreach (Int32 b in new DBConnection().ConnectDB.RezervasyonDurumuBelirle(masaID,tarih))
                deger = b;

                return Convert.ToBoolean(deger);
        }

        public static ArrayList tumMasaTipleriniCek()
        {
            ArrayList masaTipleri = new ArrayList();

            foreach (MASA_TIPI mt in new DBConnection().ConnectDB.TumMasaTipleriniCek())
                masaTipleri.Add(new MasaTipi(mt.MasaTipiID,mt.TipAdi,mt.Katsayi,mt.Resim));


            return masaTipleri;
        }

        public void masaSil(int masaID)
        {
            DBConnection cn = new DBConnection();
            cn.ConnectDB.MasaSil(masaID,Session.kullaniciKodu);
            cn.ConnectDB.SaveChanges();
            
        }

        public void masaEkle(Masa masa)
        {
            DBConnection cn = new DBConnection();
            cn.ConnectDB.MasaEkle(masa.MasaTipi.MasaTipiID,masa.Kapasite,Session.kullaniciKodu);
            cn.ConnectDB.SaveChanges();
        }

        public void masaDuzenle(Masa masa)
        {
            DBConnection cn = new DBConnection();
            cn.ConnectDB.MasaDuzenle(masa.MasaID,masa.MasaTipi.MasaTipiID,masa.Kapasite,Session.kullaniciKodu);
            cn.ConnectDB.SaveChanges();
        }
    }
}
